package com.example.login.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class MyMvcConfig implements WebMvcConfigurer {
    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        registry.addViewController("main.html").setViewName("index");
        registry.addViewController("/mobileInformation").setViewName("商品详情/手机商品详情");
        registry.addViewController("/mp3Information").setViewName("商品详情/MP3商品详情");
        registry.addViewController("/pcInformation").setViewName("商品详情/电脑商品详情");
        registry.addViewController("/登录").setViewName("登录");
        registry.addViewController("/注册").setViewName("注册");
        registry.addViewController("/order").setViewName("结算/确认订单2");
        registry.addViewController("/index").setViewName("商家中心/地址管理");
        //registry.addViewController("/个人信息管理").setViewName("商家中心/地址管理");
        registry.addViewController("/下架").setViewName("merchantLook");
        registry.addViewController("/mp3").setViewName("/商家中心/修改MP3商品");
        registry.addViewController("/pc").setViewName("/商家中心/修改电脑商品");
        registry.addViewController("/mobile").setViewName("/商家中心/修改手机商品");
        registry.addViewController("/order").setViewName("/结算/订单");
        registry.addViewController("/cart").setViewName("购物车");
        registry.addViewController("/cart2").setViewName("购物车2.0");
        registry.addViewController("/collect").setViewName("收藏夹");
        registry.addViewController("/zhekou").setViewName("商家中心/添加优惠/添加折扣优惠");
        registry.addViewController("/manjian").setViewName("商家中心/添加优惠/添加满减优惠");
        registry.addViewController("/manjian").setViewName("商家中心/添加优惠");
        registry.addViewController("/goumai").setViewName("结算/购买成功");
        registry.addViewController("/我的订单").setViewName("结算/订单");
        registry.addViewController("/商城首页").setViewName("商城首页");
//        用户的地址管理
        registry.addViewController("/address").setViewName("商家中心/地址管理");
//        商家的地址管理
        registry.addViewController("/address_1").setViewName("商家中心/地址管理1");
//        用来商家左侧栏的查看订单跳转
        registry.addViewController("/myorder").setViewName("商家中心/我的订单");
        registry.addViewController("/dataanalysis").setViewName("商家中心/数据分析");
    }
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry)
    {
        String path = System.getProperty("user.dir")+"\\src\\main\\resources\\public\\Image\\";
        registry.addResourceHandler("/Image/**")
                .addResourceLocations("file:"+path);
        registry.addResourceHandler("/user/**")
                .addResourceLocations("file:"+System.getProperty("user.dir")+"\\src\\main\\resources\\static\\");
        registry.addResourceHandler("/item/**")
                .addResourceLocations("file:"+System.getProperty("user.dir")+"\\src\\main\\resources\\static\\");
        registry.addResourceHandler("/user/getTotal/**")
                .addResourceLocations("file:"+System.getProperty("user.dir")+"\\src\\main\\resources\\static\\");
        registry.addResourceHandler("/user/**/**/**")
                .addResourceLocations("file:"+System.getProperty("user.dir")+"\\src\\main\\resources\\static\\");
        registry.addResourceHandler("/user/**/**")
                .addResourceLocations("file:"+System.getProperty("user.dir")+"\\src\\main\\resources\\static\\");
    }
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new LoginHandlerInterceptor())
                .addPathPatterns("/user/**")
                .excludePathPatterns("/index.html","/","/css/**","/img/**","/js/**");
    }
}


